// pages/classify/classify.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    maskShowed: 0,//遮罩层,为0时无遮罩层，为1时弹出遮罩层
    activeIndex: 0,//选中的tab的index
    tabList: [
      {
        id: 0,
        title: '灯具电路',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 1,
        title: '门窗家具',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 2,
        title: '卫浴洁具',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 3,
        title: '家电维修',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 4,
        title: '母婴天地',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 5,
        title: '家庭清洁',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 6,
        title: '灯具电路',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 7,
        title: '门窗家具',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 8,
        title: '卫浴洁具',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 9,
        title: '家电维修',
        imgBanner: "../../../images/goodsBanner.jpg",
      }, {
        id: 10,
        title: '家电维修',
        imgBanner: "../../../images/goodsBanner.jpg",
      }
    ],
    goodsList: [
      {
        id: 0,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲智能电饭煲智能电饭煲智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
        ]
      },
      {
        id: 1,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/bespeak.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/bespeak.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装，线路排布顶灯安装，线路排布顶灯安装，线路排布",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
        ]
      },
      {
        id: 2,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/goods.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 3,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg2.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg2.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 4,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg2.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg3.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 5,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 6,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 7,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 8,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 9,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          }
        ]
      },
      {
        id: 10,
        imgBanner: "",
        goodsItem: [
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          },
          {
            title: "智能电饭煲",
            content: "顶灯安装",
            price: "99",
            imgpath: '../../../images/uploadimg1.jpg',
            count: 0,
          }
        ]
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var goodsListBanner;
    for (var i = 0; i < this.data.tabList.length; i++) {
      console.log(this.data.tabList[i].imgBanner);
      goodsListBanner = 'goodsList[' + i + '].imgBanner';
      this.setData({
        [goodsListBanner]: this.data.tabList[i].imgBanner
      });
    }
    console.log(this.data.goodsList[0].imgBanner)
  },
  /**
   * 左边列的tab切换
   */
  tapClick: function (e) {
    console.log(e);
    this.setData({
      activeIndex: e.target.id
    })
  },
  /**
   * addCount添加数量
   */
  addCount: function (e) {
    var ind = e.currentTarget.dataset.index;//当前点击要添加的商品列表的索引值
    var count = this.data.goodsList[this.data.activeIndex].goodsItem[ind].count;//获取商品当前数量
    count++; // 点击一次商品数量 +1
    var activeI = "goodsList[" + this.data.activeIndex + "].goodsItem[" + ind + "].count";
    this.setData({
      [activeI]: count,
    });
    //console.log(this.data.goodsList[this.data.activeIndex].goodsItem[ind].count);
  },
  /**
   * reduceCount减少数量
   */
  reduceCount: function (e) {
    var ind = e.currentTarget.dataset.index;//当前点击要添加的商品列表的索引值
    var count = this.data.goodsList[this.data.activeIndex].goodsItem[ind].count;//获取商品当前数量
    count--;//点击一次商品数量就 -1,
    var activeI = "goodsList[" + this.data.activeIndex + "].goodsItem[" + ind + "].count";
    this.setData({
      [activeI]: count,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  showBill: function (e) {
    this.setData({
      maskShowed: 1,
    })
  },
  hideBill: function (e) {
    this.setData({
      maskShowed: 0,
    })
  }
})